window.onload = (event) => {
    let $purchase = {
        user: e('.user-button'),
        menu: e('.purchase-menu'),
        show: e('.right-contain'),
        form: e('.form-area')
    };
    //所有合同
    var contractShowDetail = -1; //当前点击的tr的合同编号
    var clickContract; //当前点击的一行
    var contractData; //主表信息
    var contractTablePageNum = 1;
    var contractTablePageSize = 3;

    $.ajax({
        url: 'http://www.fjemiot.cn/erp/contracts?pageNum=' + contractTablePageNum + '&pageSize=' + contractTablePageSize + '&str=""',
        success: (reply) => {
            for (var i = 0; i < reply.contracts.length; i++) {
                reply.contracts[i].supplier = reply.contracts[i].supplier.name;
                delete reply.contracts[i].details;
            }
            contractData = reply.contracts;
            let $table = tablegen(reply.contracts, ["合同号", "供应商", "日期"]);
            let tableShow = e('.table-show');
            tableShow[0].append($table);
            //查看计划表详情，点击查看详情
            $(".contractTable table tr").click(function () {
                clickContract = $(this);
                contractShowDetail = $(this).children()[0].innerText;
                console.log(contractShowDetail);
                $(".select-tr").removeClass("select-tr");
                $(this).addClass("select-tr");
            })
        },
        error: (reply) => {
            tip.alert('获取信息失败', '采购计划单', 'error', 1500);
        }
    });
    // 点击查看合同详情
    $(".add-contract").click(function () {
        if (contractShowDetail != -1) {
            console.log("疯了");
            //chooseContractTr选择的一行
            $(this).addClass("hideButton");
            $(".cel-contract").removeClass("hideButton");
            console.log("这是" + contractShowDetail)
            console.log(clickContract[0].children[2].innerText);
            clickContract.removeClass("select-tr");
            deleteRow(e(".contractTable"), 0);
            let titleName = ["合同号", "供应商", "日期"];
            let $table = tablegen([{}], titleName);
            $table.append(clickContract[0]);
            let tableShow = e('.table-show');
            tableShow[0].append($table);
            //查看采购计划详细信息
            $.ajax({
                url: "http://www.fjemiot.cn/erp/contractDetails?pageNum=1&pageSize=3&contractNo=" + contractShowDetail,
                success: (reply) => {
                    console.log(reply);
                    if (reply.contractDetails.length == 0) {
                        tip.alert('该订单详细为空', '采购计划明细单', 'error', 1500);
                    } else {
                        for (var i = 0; i < reply.contractDetails.length; i++) {
                            delete reply.contractDetails[i].contractNo;
                            reply.contractDetails[i].productNo = reply.contractDetails[i].product.productNo;
                            reply.contractDetails[i].unit = reply.contractDetails[i].product.unit;
                            reply.contractDetails[i].price = reply.contractDetails[i].product.price;
                            reply.contractDetails[i].type = reply.contractDetails[i].product.type;
                            reply.contractDetails[i].gWeight = reply.contractDetails[i].product.gWeight;
                            reply.contractDetails[i].standard = reply.contractDetails[i].product.standard;
                            reply.contractDetails[i].level = reply.contractDetails[i].product.level;
                            reply.contractDetails[i].product = reply.contractDetails[i].product.brand;
                        }
                        let tableShow = e('.table-show');
                        let $table = tablegen(reply.contractDetails,
                            ["商品品牌", "购买价格", "商品编号", "单位", "单价", "纸种", "克重", "规格", "级别"]);
                        // hideTable(tableShow[0]);
                        tableShow[0].append($table);
                        $(".cel-contract").click(function () {
                            $(this).addClass("hideButton");
                            $(".add-contract").removeClass("hideButton");
                            console.log($(tableShow[0]).children().length);
                            for (var i = 0; i <= $(tableShow[0]).children().length; i++) {
                                deleteRow(tableShow[0], 0);
                            }
                            let titleName = ["合同号", "供应商", "日期"];
                            let $purchase = tablegen(contractData, titleName);
                            tableShow[0].append($purchase);
                            $(".contractTable table tr").click(function () {
                                clickContract = $(this);
                                contractShowDetail = $(this).children()[0].innerText;
                                console.log(contractShowDetail);
                                $(".select-tr").removeClass("select-tr");
                                $(this).addClass("select-tr");
                            })
                        })
                        $(".contractTable table tr").click(function (e) {
                            e.stopPropagation();
                            $(".select-tr").removeClass("select-tr");
                            $(this).addClass("select-tr");
                            contractShowDetail = $(this)[0];
                        })
                    }
                },
                error: (reply) => {
                    tip.alert('获取信息失败', '合同明细单', 'error', 1500);
                }
            })
        }
    })

    //所有合同加分页分页加
    $(".contractTableChr").click(function () {
        contractTablePageNum++;
        $.ajax({
            url: 'http://www.fjemiot.cn/erp/contracts?pageNum=' + contractTablePageNum + '&pageSize=' + contractTablePageSize + '&str=""',
            success: (reply) => {
                if (reply.contracts != 0) {
                    for (var i = 0; i < reply.contracts.length; i++) {
                        reply.contracts[i].supplier = reply.contracts[i].supplier.name;
                        delete reply.contracts[i].details;
                    }
                    contractData = reply.contracts;
                    let $table = tablegen(reply.contracts, ["合同号", "供应商", "日期"]);
                    let tableShow = e('.table-show');
                    $($(".contractTable").children()[0]).remove();
                    tableShow[0].append($table);
                    //查看计划表详情，点击查看详情
                    $(".contractTable table tr").click(function () {
                        clickContract = $(this);
                        contractShowDetail = $(this).children()[0].innerText;
                        console.log(contractShowDetail);
                        $(".select-tr").removeClass("select-tr");
                        $(this).addClass("select-tr");
                    })
                } else {
                    tip.alert('已无数据！', '合同', '', 1500);
                }
            },
            error: (reply) => {
                tip.alert('获取信息失败', '合同', 'error', 1500);
            }
        });
    })

    $(".contractTableChl").click(function () {
        contractTablePageNum--;
        if (contractTablePageNum != 0) {
            $.ajax({
                url: 'http://www.fjemiot.cn/erp/contracts?pageNum=' + contractTablePageNum + '&pageSize=' + contractTablePageSize + '&str=""',
                success: (reply) => {
                    for (var i = 0; i < reply.contracts.length; i++) {
                        reply.contracts[i].supplier = reply.contracts[i].supplier.name;
                        delete reply.contracts[i].details;
                    }
                    contractData = reply.contracts;
                    let $table = tablegen(reply.contracts, ["合同号", "供应商", "日期"]);
                    let tableShow = e('.table-show');
                    $($(".contractTable").children()[0]).remove();
                    tableShow[0].append($table);
                    //查看计划表详情，点击查看详情
                    $(".contractTable table tr").click(function () {
                        clickContract = $(this);
                        contractShowDetail = $(this).children()[0].innerText;
                        console.log(contractShowDetail);
                        $(".select-tr").removeClass("select-tr");
                        $(this).addClass("select-tr");
                    })
                },
                error: (reply) => {
                    tip.alert('获取信息失败', '采购计划单', 'error', 1500);
                }
            });
        } else {
            tip.alert("已经是第一页", "合同", "", 1500);
        }
    })


    //所有合同加分页分页加

    var purchasePlanTablePageNum = 1;
    $(".purchasePlanTableChr").click(function () {
        tip.alert('已无数据！', '采购计划', '', 1500);
    })

    $(".purchasePlanTableChl").click(function () {
        purchasePlanTablePageNum--;
        if (purchasePlanTablePageNum != 0) {
            $.ajax({
                url: 'http://www.fjemiot.cn/erp/contracts?pageNum=' + purchasePlanTablePageNum + '&pageSize=' + contractTablePageSize + '&str=""',
                success: (reply) => {
                    for (var i = 0; i < reply.contracts.length; i++) {
                        if (reply.contracts[i].supplier.name == null) {
                            reply.contracts[i].supplier.name = "空"
                        } else {
                            reply.contracts[i].supplier = reply.contracts[i].supplier.name;
                        }
                        delete reply.contracts[i].details;
                    }
                    contractData = reply.contracts;
                    let $table = tablegen(reply.contracts, ["合同号", "供应商", "日期"]);
                    let tableShow = e('.table-show');
                    $($(".purchasePlanTable").children()[0]).remove();
                    tableShow[0].append($table);
                    //查看计划表详情，点击查看详情
                    $(".contractTable table tr").click(function () {
                        clickContract = $(this);
                        contractShowDetail = $(this).children()[0].innerText;
                        console.log(contractShowDetail);
                        $(".select-tr").removeClass("select-tr");
                        $(this).addClass("select-tr");
                    })
                },
                error: (reply) => {
                    tip.alert('获取信息失败', '采购计划单', 'error', 1500);
                }
            });
        } else {
            tip.alert("已经是第一页", "采购计划", "", 1500);
        }
    })

    //所有合同加分页分页加
    $(".purchaseTableChr").click(function () {
        tip.alert('已无数据！', '采购单', '', 1500);
    })

    $(".purchaseTableChl").click(function () {
        tip.alert("已经是第一页", "采购单", "", 1500);

    })


    //所有采购单
    var purchaseShowDetail = -1; //当前点击的tr的采购单编号
    var purchasePlanShowDetail = -1; //当前点击的tr的采购单编号
    var statusPurchase = -1; //当前点击的tr的采购计划状态
    var chooseContractTrPurchase; //tr
    var purchaseDataPurchase; //采购主表数据
    var page = 1
    $.ajax({
        url: 'http://www.fjemiot.cn/erp/purchase?pageNum=' + page + '&pageSize=5',
        success: (reply) => {
            console.log(reply);
            for (var i = 0; i < reply.value.length; i++) {
                if (reply.value[i].state == 0) {
                    reply.value[i].state = "未审核";
                } else if (reply.value[i].state == -1) {
                    reply.value[i].state = "审核不通过";
                } else if (reply.value[i].state == 1) {
                    reply.value[i].state = "审核通过未执行";
                } else if (reply.value[i].state == 2) {
                    reply.value[i].state = "审核通过且执行";
                }
            }
            let titleName = ["采购单编号", "订单日期", "供应商编号", "运费", "总价", "采购员编号", "状态", "采购计划单号"];
            let $table = tablegen(reply.value, titleName);
            purchaseDataPurchase = reply.value;
            let tableShow = e('.table-show');
            tableShow[2].append($table);
            //查看计划表详情，点击查看详情
            $(".purchaseTable table tr").click(function () {
                chooseContractTrPurchase = $(this);
                purchaseShowDetail = $(this).children()[0].innerText;
                purchasePlanShowDetail = $(this).children()[7].innerText;
                statusPurchase = $(this).children()[6].innerText;
                // alert(purchasePlanShowDetail);
                $(".select-tr").removeClass("select-tr");
                $(this).addClass("select-tr");
            })
        },
        error: (reply) => {
            tip.alert('获取信息失败', '采购计划单', 'error', 1500);
        }
    });

    //点击添加采购单出现弹框，弹框此时已有表格
    $(".add-purchase").click(function (e) {
        $("#addPurchase").removeClass("hide");
        //默认点开弹框后有表格（空的）
        console.log($(".choosePurchasePlan-table")[0]);
        var purchaseDetail = [{}];
        let $table = tablegen(purchaseDetail, ["商品品牌", "购买价格", "商品编号", "单位", "单价", "纸种", "克重", "规格", "级别"]);
        $(".choosePurchasePlan-table")[0].append($table);
    })
    //点击选择采购计划单(将采购计划主表渲染)
    var selectpurchasePlanDetail = []; //当前选择的商品
    var purchasePostData = {}; //最终传给后台的数据
    $(".choosePurchasePlanBottom").click(function () {
        $(".purchasePlanZhu").removeClass("hide");
        $("#addPurchase").addClass("hide");
        $.ajax({
            url: 'http://www.fjemiot.cn/erp/purchasePlans?pageNum=1&pageSize=3',
            success: (reply) => {
                for (var i = 0; i < reply.purchasePlans.length && reply.purchasePlans[i].contract.contractNo != null; i++) {
                    reply.purchasePlans[i].contract = reply.purchasePlans[i].contract.contractNo;
                    reply.purchasePlans[i].employee = reply.purchasePlans[i].employee.name;
                    reply.purchasePlans[i].supplier = reply.purchasePlans[i].supplier.name;
                    status = reply.purchasePlans[i].state;
                    if (reply.purchasePlans[i].state == 0) {
                        reply.purchasePlans[i].state = "未审核";
                    } else if (reply.purchasePlans[i].state == -1) {
                        reply.purchasePlans[i].state = "审核不通过";
                    } else if (reply.purchasePlans[i].state == 1) {
                        reply.purchasePlans[i].state = "审核通过未执行";
                    }
                    delete reply.purchasePlans[i].details;
                }
                let titleName = ["采购计划编号", "供应商", "合同号", "计划日期", "采购员", "状态"];

                let $table = tablegen(reply.purchasePlans, titleName);
                purchaseData = reply.purchasePlans;
                let tableShow = e(".purchasePlanZhu-table .zhu");
                console.log($(".purchasePlanZhu-table .zhu").children());
                if ($(".purchasePlanZhu-table .zhu").children().length < 2) {
                    tableShow.append($table);
                }
                //点击合同主表中的一条
                $('.purchasePlanZhu-table table tr').click(function () {
                    var purchasePlanNo = $(this).children()[0].innerText;
                    if (e(".purchasePlanZhu-table .ci").children.length > 1) {
                        deleteRow(e(".purchasePlanZhu-table .ci"), 1);
                    }
                    showTable(e(".purchasePlanZhu-table .ci"));
                    //添加采购计划的详细表
                    $.ajax({
                        url: 'http://www.fjemiot.cn/erp/purchasePlanDetails?pageNum=1&pageSize=3&planNo=' + purchasePlanNo,
                        success: (reply) => {
                            // alert(purchasePlanNo);
                            console.log(reply);
                            if (reply.purchasePlanDetails.length == 0) {
                                tip.alert('该计划详细为空', '采购计划明细单', 'error', 1500);
                            } else {
                                for (var i = 0; i < reply.purchasePlanDetails.length; i++) {
                                    delete reply.purchasePlanDetails[i].planNo;
                                    reply.purchasePlanDetails[i].productNo = reply.purchasePlanDetails[i].product.productNo;
                                    reply.purchasePlanDetails[i].brand = reply.purchasePlanDetails[i].product.brand;
                                    reply.purchasePlanDetails[i].unit = reply.purchasePlanDetails[i].product.unit;
                                    reply.purchasePlanDetails[i].type = reply.purchasePlanDetails[i].product.type;
                                    reply.purchasePlanDetails[i].price = reply.purchasePlanDetails[i].product.price;
                                    reply.purchasePlanDetails[i].gWeight = reply.purchasePlanDetails[i].product.gWeight;
                                    reply.purchasePlanDetails[i].standard = reply.purchasePlanDetails[i].product.standard;
                                    reply.purchasePlanDetails[i].product = reply.purchasePlanDetails[i].product.level;
                                }
                                // hideTable(tableShow[0]);
                                let $table = tablegen(reply.purchasePlanDetails, ["级别", "购买价格", "商品编号", "商品品牌", "单位", "纸种", "单价", "克重", "规格", ]);
                                let tableShow = e('.purchasePlanZhu-table .ci');
                                tableShow.append($table);
                                var tr;
                                //从明细表里通过点击将选取的消失
                                $('.purchasePlanZhu-table .ci table tr').click(function () {
                                    // var productNo = $(this).children()[2].innerText;
                                    // var purchasePrice = $(this).children()[1].innerText;
                                    selectpurchasePlanDetail.push($(this));
                                    tr = $(this);
                                    // alert("kkkk");
                                    $(".purchaseUserZhu").removeClass("hide");
                                    $(".purchaseUserZhu-commit").click(function () {
                                        $(".purchaseUserZhu").addClass("hide");
                                        var productNo = tr.children()[2].innerText;
                                        var purchasePrice = tr.children()[1].innerText;
                                        selectContractDetail.push(tr);
                                        var obj = {};
                                        obj.purchasePrice = parseInt(purchasePrice);
                                        obj.product = {
                                            "productNo": parseInt(productNo)
                                        }
                                        tr.remove();
                                    })
                                    $(".purchaseUserZhu-cancel").click(function () {
                                        $(".purchasePlanZhu-table .ci table").append(tr);
                                        $(".purchaseUserZhu").addClass("hide");
                                    })
                                    // var obj = {};
                                    // obj.purchasePrice = parseInt(purchasePrice);
                                    // obj.product = {
                                    //     "productNo": parseInt(productNo)
                                    // }
                                    // details.push(obj);
                                    // selectpurchasePlanDetail.details = details;
                                    $(this).remove();
                                    // console.log(selectpurchasePlanDetail);
                                    // console.log(selectpurchasePlanDetail);
                                    // $('.purchasePlanZhu-table .ci table').append(selectpurchasePlanDetail[0]);
                                })
                                //选择合同详情结束，在添加计划时显示


                            }
                        },
                        error: (reply) => {
                            tip.alert('获取信息失败', '采购计划明细单', 'error', 1500);
                        }
                    })
                })
                $(".choosePurchasePlanDetailCancel").click(function () {
                    $(".purchasePlanZhu").addClass("hide");
                    $("#addPurchase").removeClass("hide");
                })
                $(".choosePurchasePlanDetail").click(function () {
                    $(".purchasePlanZhu").addClass("hide");
                    $("#addPurchase").removeClass("hide");
                    console.log(selectpurchasePlanDetail);
                    for (var i = 0; i < selectpurchasePlanDetail.length; i++) {
                        $("#addPurchase .choosePurchasePlan-table table").append(selectpurchasePlanDetail[i])
                    }
                })
            },
            error: (reply) => {
                tip.alert('获取信息失败', '采购计划单', 'error', 1500);
            }
        });

    })
    //添加采购时点击提交
    $(".PurchasePlan-submit").click(function () {
        if (purchasePostData == {}) {
            tip.alert("添加数据为空！", "", 'error', 1500);
        } else {
            console.log(JSON.stringify(purchasePostData));
            $(".purchaseUserZhu").removeClass("hide");
            // $("#addPurchase .choosePurchasePlan-table table").remove();
            // var purchaseDetail = [{}];
            // let $table = tablegen(purchaseDetail, ["级别", "商品品牌", "购买价格", "商品编号", "单位", "单价", "纸种", "克重", "规格"]);
            // $(".chooseContract-table")[0].append($table);
        }
    })
    //添加采购表单中点击取消
    $(".purchaseUserZhu-cancel").click(function () {
        $(".purchaseUserZhu").addClass("hide");
        $($("#addPurchase")).addClass("hide");
    })

    $(".PurchasePlan-cancel").click(function () {
        $(".purchaseUserZhu").addClass("hide");
        $($("#addPurchase")).addClass("hide");
    })
    //添加采购主表信息，点击确定
    $(".purchaseUserZhu-commit").click(function () {
        $(".purchaseUserZhu").addClass("hide");
        $($("#addPurchase")).addClass("hide");
        // alert("提交添加的采购单！");
        // $.ajax({
        //     url: "http://www.fjemiot.cn/erp/purchasePlan",
        //     type: 'post',
        //     data: JSON.stringify(purchasePlanPostData),
        //     contentType: 'application/json',
        //     success: reply => {
        //         if (reply == 1001) {
        //             alert("成功！");
        //         } else {
        //             alert("失败！")
        //         }
        //     },
        //     error: reply => {}
        // })
    })
    //采购表点击查看详情
    var currentPurchaseShowDetail; //当前订单表详细表点击
    var currentPurchasePlanNo; //当前订单表所属计划号
    var alreadyTrPurchase = []; //当前订单详情中已有的tr数组
    var clickPurchasePlan; //当前点击的一行
    $(".purchase-search").click(function () {
        if (purchaseShowDetail != -1) {
            console.log("疯了");
            //chooseContractTr选择的一行
            $(".cal-purchase").removeClass("hideButton");
            $("#add-purchaseDetail").removeClass("hideButton");
            $(this).addClass("hideButton");
            console.log("这是" + purchaseShowDetail)
            console.log(chooseContractTrPurchase[0].children[2].innerText);
            currentPurchasePlanNo = chooseContractTrPurchase[0].children[7].innerText;
            chooseContractTrPurchase.removeClass("select-tr");
            deleteRow(e(".purchaseTable"), 0);
            let titleName = ["采购单编号", "订单日期", "供应商编号", "运费", "总价", "采购员编号", "状态", "采购计划单编号"];
            let $table = tablegen([{}], titleName);
            $table.append(chooseContractTrPurchase[0]);
            let tableShow = e('.table-show');
            tableShow[2].append($table);
            //查看采购计划详细信息
            $.ajax({
                url: "http://www.fjemiot.cn/erp/purchaseDetail/1/3/" + purchaseShowDetail,
                success: (reply) => {
                    console.log(reply);
                    if (reply.value.length == 0) {
                        tip.alert('该订单详细为空', '采购计划明细单', 'error', 1500);
                    } else {
                        for (var i = 0; i < reply.value.length; i++) {
                            delete reply.value[i].orderNo;
                            reply.value[i].productNo = reply.value[i].product.productNo;
                            reply.value[i].brand = reply.value[i].product.brand;
                            reply.value[i].unit = reply.value[i].product.unit;
                            reply.value[i].type = reply.value[i].product.type;
                            reply.value[i].price = reply.value[i].product.price;
                            reply.value[i].gWeight = reply.value[i].product.gWeight;
                            reply.value[i].standard = reply.value[i].product.standard;
                            reply.value[i].product = reply.value[i].product.level;
                        }
                        let tableShow = e('.table-show');
                        // hideTable(tableShow[0]);
                        let $table = tablegen(reply.value, ["数量", "单价", "级别", "商品编号", "商品品牌", "单位", "纸种", "克重", "规格", ]);
                        tableShow[2].append($table);
                        alreadyTrPurchase = $table.children;
                        $(".cal-purchase").click(function () {
                            $(this).addClass("hideButton");
                            $("#add-purchaseDetail").addClass("hideButton");
                            $(".purchase-search").removeClass("hideButton");
                            console.log($(tableShow[2]).children().length);
                            for (var i = 0; i <= $(tableShow[2]).children().length; i++) {
                                deleteRow(tableShow[2], 0);
                            }
                            let titleName = ["采购单编号", "订单日期", "供应商编号", "运费", "总价", "采购员编号", "状态", "采购计划单号"];
                            let $purchase = tablegen(purchaseDataPurchase, titleName);
                            tableShow[2].append($purchase);
                            $(".purchaseTable table tr").click(function () {
                                chooseContractTrPurchase = $(this);
                                purchaseShowDetail = $(this).children()[0].innerText;
                                console.log(purchaseShowDetail);
                                $(".select-tr").removeClass("select-tr");
                                $(this).addClass("select-tr");
                                clickPurchasePlan = $(this);

                            })
                        })
                        $(".purchaseTable table tr").click(function (e) {
                            clickPurchasePlan = $(this);
                            e.stopPropagation();
                            $(".select-tr").removeClass("select-tr");
                            $(this).addClass("select-tr");
                            currentPurchaseShowDetail = $(this)[0];
                        })
                    }
                },
                error: (reply) => {
                    tip.alert('获取信息失败', '采购计划明细单', 'error', 1500);
                }
            })
        }
    })
    //采购计划表点击添加详细信息
    var addPurchaseDetailData = [];
    $("#add-purchaseDetail").click(function () {
        if (currentPurchasePlanNo != undefined) {
            $.ajax({
                url: 'http://www.fjemiot.cn/erp/purchasePlanDetails?pageNum=1&pageSize=3&planNo=' + currentPurchasePlanNo,
                success: (reply) => {
                    if (reply.purchasePlanDetails.length == 0) {
                        tip.alert('该计划详细为空', '采购计划明细单', 'error', 1500);
                    } else {
                        $(".addPurchaseDetailAlert").removeClass("hide");
                        for (var i = 0; i < reply.purchasePlanDetails.length; i++) {
                            delete reply.purchasePlanDetails[i].planNo;
                            reply.purchasePlanDetails[i].productNo = reply.purchasePlanDetails[i].product.productNo;
                            reply.purchasePlanDetails[i].brand = reply.purchasePlanDetails[i].product.brand;
                            reply.purchasePlanDetails[i].unit = reply.purchasePlanDetails[i].product.unit;
                            reply.purchasePlanDetails[i].type = reply.purchasePlanDetails[i].product.type;
                            reply.purchasePlanDetails[i].price = reply.purchasePlanDetails[i].product.price;
                            reply.purchasePlanDetails[i].gWeight = reply.purchasePlanDetails[i].product.gWeight;
                            reply.purchasePlanDetails[i].standard = reply.purchasePlanDetails[i].product.standard;
                            reply.purchasePlanDetails[i].product = reply.purchasePlanDetails[i].product.level;
                        }
                        let tableShow = e('.purchaseDetail-table');
                        // hideTable(tableShow[0]);
                        let $table = tablegen(reply.purchasePlanDetails, ["级别", "购买价格", "商品编号", "商品品牌", "单位", "纸种", "单价", "克重", "规格", ]);
                        for (var i = 0; i < $table.children.length; i++) {
                            if ($table.children[i] == alreadyTr[i]) {
                                deleteRow("purchaseDetail-table", i);
                            }
                        }
                        if (tableShow.children.length < 1) {
                            tableShow.append($table);
                        }

                        //从明细表里通过点击将选取的消失
                        var chacheTarget = 0; //保存添加了几条
                        $('.purchaseDetail-table table tr').click(function () {
                            addPurchaseDetailData.push($(this)[0]);
                            console.log("这呢")
                            console.log($(this).children()[0]);
                            $(this).append("<td>20</td>");
                            var deleteTd = $(this).children()[1];
                            $(deleteTd).remove();
                            $($(this).children()[3]).insertBefore($($(this).children()[0]));
                            $($(this).children()[8]).insertBefore($($(this).children()[0]));
                            $($(this).children()[6]).insertBefore($($(this).children()[1]));
                            $($(this).children()[3]).insertBefore($($(this).children()[2]));
                            $($(this).children()[4]).insertBefore($($(this).children()[3]))
                            $($(this).children()[5]).insertBefore($($(this).children()[4]))
                            $(this).remove();
                            let tableShow = $(".purchaseTable table")[1];
                            tableShow.append($(this)[0]);
                            chacheTarget = chacheTarget + 1;
                        })
                        $(".cancel-addPurchaseDetail").click(function () {
                            let tableShowDetail = $(".purchaseTable table")[1];
                            console.log(tableShowDetail);
                            for (var i = 0; i < chacheTarget; i++) {
                                deleteRow($(tableShowDetail)[0], $(tableShowDetail)[0].children.length - 1);
                            }
                            $(".addPurchaseDetailAlert").addClass("hide");
                        })
                        $(".commit-addPurchaseDetail").click(function () {
                            $(".addPurchaseDetailAlert").addClass("hide");
                            console.log("新添加了一条数据到订单表明细中")
                        })
                    }
                },
                error: (reply) => {
                    tip.alert('获取信息失败', '采购计划明细单', 'error', 1500);
                }
            })
        } else {
            tip.alert("请点击操作的采购单", "采购单", "", 1500)
        }
    })

    //采购表点击修改
    $(".upd-purchase").click(function (e) {
        e.stopPropagation();
        console.log(clickPurchasePlan); //次表点击的一行
        console.log(chooseContractTrPurchase); //主表点击的一行
        console.log(chooseContractTrPurchase.children());
        var zhuData = []; //主表的数据
        var detailsData = [] //明细的数据
        for (var i = 0; i < chooseContractTrPurchase.children().length; i++) {
            console.log(chooseContractTrPurchase.children()[i].innerText);
            zhuData.push(chooseContractTrPurchase.children()[i].innerText);
        }
        if (statusPurchase.indexOf("审核通过") == -1 || statusPurchase.indexOf("未执行") != -1) {
            if (clickPurchasePlan != undefined) {
                if (clickPurchasePlan.children().length == 9) {
                    $(".purchaseUserZhu input").val(clickPurchasePlan.children()[0].innerText);
                    //修改明细
                    var yiChu = [10, 20, 30, 40, 50, 100, 150, 200, 250, 300];
                    $(".purchaseUserZhu").removeClass("hide");
                    $(".purchaseUserZhu-commit").click(function () {
                        if (getElements("purchaseUserZhu") > yiChu[5]) {
                            tip.alert("设置失败，库存溢出！", "采购", "error", 1500);
                        } else {
                            console.log(getElements("purchaseUserZhu"));
                            clickPurchasePlan.children()[0].innerText = getElements("purchaseUserZhu");
                            $(".purchaseUserZhu").addClass("hide");
                            tip.alert("修改商品数量成功！", "采购", "success", 1500);
                        }
                    })
                    $(".purchaseUserZhu-cancel").click(function () {
                        $(".purchaseUserZhu").addClass("hide");
                    })
                    // alert("修改数量！");
                    return;
                } else {
                    tip.alert("此处不可修改采购单主要信息！", "采购", "error", 1500);
                }
            }
            if (chooseContractTrPurchase != undefined) {
                $(".purchaseUserDetail").removeClass("hide");
                $(".purchaseUserDetail input")[0].value = zhuData[3];
                $(".purchaseUserDetail-commit").click(function () {
                    e.stopPropagation();
                    console.log(getElements("purchaseUserDetail"));
                    zhuData[3] = getElements("purchaseUserDetail");
                    for (var i = 0; i < chooseContractTrPurchase.children().length; i++) {
                        chooseContractTrPurchase.children()[i].innerText = zhuData[i];
                    }
                    $(".purchaseUserDetail").addClass("hide");
                    tip.alert("修改运费成功！", "采购", "success", 1500);
                    return;
                })
                $(".purchaseUserDetail-cancel").click(function () {
                    e.stopPropagation();
                    $(".purchaseUserDetail").addClass("hide");
                })
            }
        } else {
            tip.alert("此计划已审核，不可进行操作！", "计划", "error", 1500);
            return;
        }
    })
    //采购点击删除
    $(".del-purchase").click(function () {
        if (statusPurchase.indexOf("审核通过") == -1 || statusPurchase.indexOf("未执行") != -1) {
            if (clickPurchasePlan != undefined) {
                console.log(clickPurchasePlan.children().length); //次表点击的一行
                console.log(chooseContractTrPurchase); //主表点击的一行
                if (clickPurchasePlan.children().length == 9) {
                    //删除明细
                    $(clickPurchasePlan).remove();
                    tip.alert("删除成功", "订单表", "success", 1500);
                    return;
                } else if (clickPurchasePlan.children().length == 8) {
                    tip.alert("此处不可删除", "订单主表", "error", 1500);
                    return;
                }
            } else {
                //删除整张表
                $(chooseContractTrPurchase).remove();
                tip.alert("删除成功", "订单表", "success", 1500);
                return;
            }
        } else {
            tip.alert("此计划已审核，不可进行操作！", "订单", "error", 1500);
            return;
        }
    })




    // 采购计划
    //所有采购计划
    var purchasePlanShowDetail = -1; //当前点击的tr的采购计划编号
    var status = -1; //当前点击的tr的采购计划状态
    var chooseContractTr; //tr
    var purchasePlansData; //采购计划主表数据
    $.ajax({
        url: 'http://www.fjemiot.cn/erp/purchasePlans?pageNum=1&pageSize=3',
        success: (reply) => {
            console.log(reply);
            for (var i = 0; i < reply.purchasePlans.length && reply.purchasePlans[i].contract.contractNo != null; i++) {
                reply.purchasePlans[i].contract = reply.purchasePlans[i].contract.contractNo;
                reply.purchasePlans[i].employee = reply.purchasePlans[i].employee.name;
                reply.purchasePlans[i].supplier = reply.purchasePlans[i].supplier.name;
                if (reply.purchasePlans[i].state == 0) {
                    reply.purchasePlans[i].state = "未执行";
                } else if (reply.purchasePlans[i].state == 1) {
                    reply.purchasePlans[i].state = "已执行";
                }
                delete reply.purchasePlans[i].details;
            }
            let titleName = ["采购计划编号", "供应商", "合同号", "计划日期", "总经理", "状态"];

            let $table = tablegen(reply.purchasePlans, titleName);
            purchasePlansData = reply.purchasePlans;
            let tableShow = e('.table-show');
            tableShow[1].append($table);
            //查看计划表详情，点击查看详情
            $(".purchasePlanTable table tr").click(function () {
                chooseContractTr = $(this);
                status = $(this).children()[5].innerText;
                purchasePlanShowDetail = $(this).children()[0].innerText;
                console.log(purchasePlanShowDetail);
                $(".select-tr").removeClass("select-tr");
                $(this).addClass("select-tr");
            })

        },
        error: (reply) => {
            tip.alert('获取信息失败', '采购计划单', 'error', 1500);
        }
    });

    //点击左侧的菜单右侧动态改变 
    $purchase.menu.addEventListener('click', (event) => {
        if (event.target.tagName === 'LI') {
            let oldSelect = e('.select');
            if (typeof oldSelect !== 'undefined') oldSelect.classList.remove('select');
            event.target.classList.add('select');
            for (let showBox of $purchase.show.children)
                if (showBox.querySelector('.title').innerText === event.target.innerText) {
                    showBox.classList.remove('hide');
                    showBox.classList.add('show');
                } else {
                    showBox.classList.remove('show');
                    showBox.classList.add('hide');
                }
        }

    });
    //默认合同被选中,改变背景色
    $($($purchase.menu).find("li")[0]).addClass("select");

    //点击添加采购计划出现弹框，弹框此时已有表格
    $(".add-purchasePlan").click(function (e) {
        $("#addPurchasePlan").removeClass("hide");
        //默认点开弹框后有表格（空的）
        console.log($(".chooseContract-table")[0]);
        var purchasePlanDetail = [{}];
        let $table = tablegen(purchasePlanDetail, ["商品品牌", "购买价格", "商品编号", "单位", "单价", "纸种", "克重", "规格", "级别"]);
        $(".chooseContract-table")[0].append($table);
    })
    //点击选择合同(将合同主表渲染)
    var selectContractDetail = []; //当前选择的商品
    var purchasePlanPostData = {}; //最终传给后台的数据
    $(".chooseContractBottom").click(function () {
        $(".contractZhu").removeClass("hide");
        $("#addPurchasePlan").addClass("hide");
        $.ajax({
            url: 'http://www.fjemiot.cn/erp/contracts?pageNum=1&pageSize=3&str=""',
            success: (reply) => {
                var contractNo = 0;
                var supplierNo = 0;
                var planDate = "";
                var details = [];
                for (var i = 0; i < reply.contracts.length; i++) {
                    supplierNo = reply.contracts[i].supplier.supplierNo;
                    reply.contracts[i].supplier = reply.contracts[i].supplier.name;
                    contractNo = reply.contracts[i].contractNo;
                    delete reply.contracts[i].details;
                }
                // alert(supplierNo);
                console.log(reply.contracts[0].contractNo);
                purchasePlanPostData.contract = {
                    "contractNo": contractNo
                };
                purchasePlanPostData.supplier = {
                    "supplierNo": parseInt(supplierNo)
                };
                var date = new Date();
                var year = date.getFullYear();
                var mouth = date.getMonth();
                var day = date.getDate();
                planDate = year + "-" + (mouth + 1) + "-" + day;
                purchasePlanPostData.planDate = planDate;
                purchasePlanPostData.state = "0";
                //后期获取当前登录的人员id
                purchasePlanPostData.employee = {
                    "employeeNo": 1001
                }
                let $table = tablegen(reply.contracts, ["合同号", "供应商", "日期"]);
                let tableShow = e(".contractZhu-table .zhu");
                if ($(".contractZhu-table .zhu").children().length < 2) {
                    tableShow.append($table);
                }
                //点击合同主表中的一条
                $('.contractZhu-table table tr').click(function () {
                    var contractNo = $(this).children()[0].innerText;
                    if (e(".contractZhu-table .ci").children.length > 1) {
                        deleteRow(e(".contractZhu-table .ci"), 1);
                    }
                    showTable(e(".contractZhu-table .ci"));
                    //添加合同的详细表
                    $.ajax({
                        url: 'http://www.fjemiot.cn/erp/contractDetails?pageNum=1&pageSize=3&contractNo=' + contractNo,
                        success: (reply) => {
                            if (reply.contractDetails.length == 0) {
                                tip.alert('获取信息失败', '采购计划明细单', 'error', 1500);
                            } else {
                                for (var i = 0; i < reply.contractDetails.length; i++) {
                                    delete reply.contractDetails[i].contractNo;
                                    reply.contractDetails[i].productNo = reply.contractDetails[i].product.productNo;
                                    reply.contractDetails[i].unit = reply.contractDetails[i].product.unit;
                                    reply.contractDetails[i].price = reply.contractDetails[i].product.price;
                                    reply.contractDetails[i].type = reply.contractDetails[i].product.type;
                                    reply.contractDetails[i].gWeight = reply.contractDetails[i].product.gWeight;
                                    reply.contractDetails[i].standard = reply.contractDetails[i].product.standard;
                                    reply.contractDetails[i].level = reply.contractDetails[i].product.level;
                                    reply.contractDetails[i].product = reply.contractDetails[i].product.brand;
                                }
                                let tableShow = e('.contractZhu-table .ci');
                                let $table = tablegen(reply.contractDetails,
                                    ["商品品牌", "购买价格", "商品编号", "单位", "单价", "纸种", "克重", "规格", "级别"]);
                                tableShow.append($table);
                                //从明细表里通过点击将选取的消失
                                $('.contractZhu-table .ci table tr').click(function () {
                                    var tr = $(this);
                                    var productNo = tr.children()[2].innerText;
                                    var purchasePrice = tr.children()[1].innerText;
                                    selectContractDetail.push(tr);
                                    var obj = {};
                                    obj.purchasePrice = parseInt(purchasePrice);
                                    obj.product = {
                                        "productNo": parseInt(productNo)
                                    }
                                    details.push(obj);
                                    purchasePlanPostData.details = details;
                                    tr.remove();
                                    // console.log(selectContractDetail);
                                    // console.log(purchasePlanPostData);
                                    // $('.contractZhu-table .ci table').append(selectContractDetail[0]);
                                })

                            }
                        },
                        error: (reply) => {
                            tip.alert('获取信息失败', '采购计划明细单', 'error', 1500);
                        }
                    })
                })
                //选择合同详情结束，在添加计划时显示
                $(".chooseContractDetail").click(function () {
                    $(".contractZhu").addClass("hide");
                    $("#addPurchasePlan").removeClass("hide");
                    for (var i = 0; i < selectContractDetail.length; i++) {
                        $("#addPurchasePlan .chooseContract-table table").append(selectContractDetail[i])
                    }
                })
            },
            error: (reply) => {
                tip.alert('获取信息失败', '采购计划单', 'error', 1500);
            }
        });

    })

    //添加采购计划时点击提交
    $(".contract-submit").click(function () {
        if (purchasePlanPostData == {}) {
            tip.alert("添加数据为空！", "", 'error', 1500);
        } else {
            console.log(JSON.stringify(purchasePlanPostData));
            $("#addPurchasePlan .chooseContract-table table").remove();
            var purchasePlanDetail = [{}];
            let $table = tablegen(purchasePlanDetail, ["商品品牌", "购买价格", "商品编号", "单位", "单价", "纸种", "克重", "规格", "级别"]);
            $(".chooseContract-table")[0].append($table);
            $.ajax({
                url: "http://www.fjemiot.cn/erp/purchasePlan",
                type: 'post',
                data: JSON.stringify(purchasePlanPostData),
                contentType: 'application/json',
                success: reply => {
                    if (reply == 1001) {
                        // alert("成功！");
                        tip.alert("操作成功！", "", "success", 1500);
                        $(".addPurchasePlan").addClass("hide");
                    } else {
                        tip.alert("操作失败！", "", "error", 1500);
                        // alert("失败！")
                    }
                },
                error: reply => {}
            })
        }
    })
    //添加采购计划表单中点击取消
    $(".contract-cancel").click(function () {
        $($("#addPurchasePlan")).addClass("hide");
    })

    //采购计划表点击查看详情
    var currentPurchasePlanShowDetail; //当前订单计划表详细表点击
    var currentPurchasePlanContractNo; //当前订单计划表所属合同号
    var alreadyTr = []; //当前订单计划详情中已有的tr数组
    var PurchasePlantr; //当前采购计划详细点击信息
    $(".contract-search").click(function () {
        if (purchasePlanShowDetail != -1) {
            console.log("疯了");
            //chooseContractTr选择的一行
            $(".cal-purchasePlan").removeClass("hideButton");
            $("#add-purchasePlanDetail").removeClass("hideButton");
            $(this).addClass("hideButton");
            console.log("这是" + purchasePlanShowDetail)
            console.log(chooseContractTr[0].children[2].innerText);
            currentPurchasePlanContractNo = chooseContractTr[0].children[2].innerText;
            chooseContractTr.removeClass("select-tr");
            deleteRow(e(".purchasePlanTable"), 0);
            let titleName = ["采购计划编号", "供应商", "合同号", "计划日期", "采购员", "状态"];
            let $table = tablegen([{}], titleName);
            $table.append(chooseContractTr[0]);
            let tableShow = e('.table-show');
            tableShow[1].append($table);
            //查看采购计划详细信息
            $.ajax({
                url: 'http://www.fjemiot.cn/erp/purchasePlanDetails?pageNum=1&pageSize=3&planNo=' + purchasePlanShowDetail,
                success: (reply) => {
                    console.log(reply);
                    if (reply.purchasePlanDetails.length == 0) {
                        tip.alert('该计划详细为空', '采购计划明细单', 'error', 1500);
                    } else {
                        for (var i = 0; i < reply.purchasePlanDetails.length; i++) {
                            delete reply.purchasePlanDetails[i].planNo;
                            reply.purchasePlanDetails[i].productNo = reply.purchasePlanDetails[i].product.productNo;
                            reply.purchasePlanDetails[i].brand = reply.purchasePlanDetails[i].product.brand;
                            reply.purchasePlanDetails[i].unit = reply.purchasePlanDetails[i].product.unit;
                            reply.purchasePlanDetails[i].type = reply.purchasePlanDetails[i].product.type;
                            reply.purchasePlanDetails[i].price = reply.purchasePlanDetails[i].product.price;
                            reply.purchasePlanDetails[i].gWeight = reply.purchasePlanDetails[i].product.gWeight;
                            reply.purchasePlanDetails[i].standard = reply.purchasePlanDetails[i].product.standard;
                            reply.purchasePlanDetails[i].product = reply.purchasePlanDetails[i].product.level;
                        }
                        let tableShow = e('.table-show');
                        // hideTable(tableShow[0]);
                        let $table = tablegen(reply.purchasePlanDetails, ["级别", "购买价格", "商品编号", "商品品牌", "单位", "纸种", "单价", "克重", "规格", ]);
                        tableShow[1].append($table);
                        alreadyTr = $table.children;

                        $(".purchasePlanTable table tr").click(function (e) {
                            e.stopPropagation();
                            $(".select-tr").removeClass("select-tr");
                            $(this).addClass("select-tr");
                            currentPurchasePlanShowDetail = $(this)[0];
                            PurchasePlantr = $(this);
                        })
                    }
                },
                error: (reply) => {
                    tip.alert('获取信息失败', '采购计划明细单', 'error', 1500);
                }
            })
            $(".cal-purchasePlan").click(function () {
                $(this).addClass("hideButton");
                $("#add-purchasePlanDetail").addClass("hideButton");
                $(".contract-search").removeClass("hideButton");
                console.log($(tableShow[1]).children().length);
                for (var i = 0; i <= $(tableShow[1]).children().length; i++) {
                    deleteRow(tableShow[1], 0);
                }
                console.log(tableShow[1]);
                let titleName = ["采购计划编号", "供应商", "合同号", "计划日期", "采购员", "状态"];
                let $purchasePlan = tablegen(purchasePlansData, titleName);
                tableShow[1].append($purchasePlan);
                $(".purchasePlanTable table tr").click(function () {
                    chooseContractTr = $(this);
                    purchasePlanShowDetail = $(this).children()[0].innerText;
                    console.log(purchasePlanShowDetail);
                    $(".select-tr").removeClass("select-tr");
                    $(this).addClass("select-tr");
                })
            })
        }
    })

    //采购计划表点击添加详细信息
    var addPurchasePlanDetailData = [];
    $("#add-purchasePlanDetail").click(function () {
        if (currentPurchasePlanContractNo != undefined) {
            $.ajax({
                url: 'http://www.fjemiot.cn/erp/contractDetails?pageNum=1&pageSize=3&contractNo=' + currentPurchasePlanContractNo,
                success: (reply) => {
                    if (reply.contractDetails.length == 0) {
                        tip.alert('获取信息失败', '采购计划明细单', 'error', 1500);
                    } else {
                        $(".addPurchasePlanDetailAlert").removeClass("hide");
                        for (var i = 0; i < reply.contractDetails.length; i++) {
                            delete reply.contractDetails[i].contractNo;
                            reply.contractDetails[i].productNo = reply.contractDetails[i].product.productNo;
                            reply.contractDetails[i].unit = reply.contractDetails[i].product.unit;
                            reply.contractDetails[i].price = reply.contractDetails[i].product.price;
                            reply.contractDetails[i].type = reply.contractDetails[i].product.type;
                            reply.contractDetails[i].gWeight = reply.contractDetails[i].product.gWeight;
                            reply.contractDetails[i].standard = reply.contractDetails[i].product.standard;
                            reply.contractDetails[i].level = reply.contractDetails[i].product.level;
                            reply.contractDetails[i].product = reply.contractDetails[i].product.brand;
                        }
                        let tableShow = $('.purchasePlanDetail-table')[0];
                        let $table = tablegen(reply.contractDetails,
                            ["商品品牌", "购买价格", "商品编号", "单位", "单价", "纸种", "克重", "规格", "级别"]);
                        for (var i = 0; i < $table.children.length; i++) {
                            if ($table.children[i] == alreadyTr[i]) {
                                deleteRow("purchasePlanDetail-table", i);
                            }
                        }
                        tableShow.append($table);
                        //从明细表里通过点击将选取的消失
                        var chacheTarget = 0; //保存添加了几条
                        $('.purchasePlanDetail-table table tr').click(function () {
                            addPurchasePlanDetailData.push($(this)[0]);
                            console.log("这呢")
                            console.log($(this).children()[0]);
                            $($(this).children()[8]).insertBefore($($(this).children()[0]));
                            $($(this).children()[2]).insertBefore($($(this).children()[1]));
                            $($(this).children()[3]).insertBefore($($(this).children()[2]));
                            $($(this).children()[6]).insertBefore($($(this).children()[5]))
                            // $("ul li:eq(2)").insertAfter("ul li:eq(4)"); 
                            $(this).remove();
                            console.log(addPurchasePlanDetailData);
                            let tableShow = $(".purchasePlanTable table")[1];
                            chacheTarget = chacheTarget + 1;
                            console.log(tableShow);
                            tableShow.append($(this)[0]);
                        })
                        $(".cancel-addPurchasePlanDetail").click(function () {
                            let tableShowDetail = $(".purchasePlanTable table")[1];
                            for (var i = 0; i < chacheTarget; i++) {
                                deleteRow($(tableShowDetail)[0], $(tableShowDetail)[0].children.length - 1);
                            }
                            $(".addPurchasePlanDetailAlert").addClass("hide");
                        })
                        $(".commit-addPurchasePlanDetail").click(function () {
                            $(".addPurchasePlanDetailAlert").addClass("hide");
                            console.log("新添加了一条数据到计划表明细中")
                        })
                    }
                },
                error: (reply) => {
                    tip.alert('获取信息失败', '采购计划明细单', 'error', 1500);
                }
            })
        } else {
            tip.alert("请点击操作的采购计划", "采购计划", "", 1500)
        }
    })


    //采购计划表点击主表进行修改
    var purchasePlanZhuChangeData = []; //采购计划表修改主表的数据
    // 采购计划表修改主表弹框
    var beginData = [];

    function changePurchasePlan(e) {
        console.log("这是");
        window.event ? window.event.cancelBubble = true : e.stopPropagation();
        if (purchasePlanShowDetail != -1) {
            $(".purchasePlanZhuChange").removeClass("hide");
            purchasePlanZhuChangeData = [];
            for (var i = 0; i < chooseContractTr.children().length; i++) {
                purchasePlanZhuChangeData.push(chooseContractTr.children()[i].innerText);
            }
            //原数据
            beginData = purchasePlanZhuChangeData.slice();
            console.log(purchasePlanZhuChangeData);
            purchasePlanZhuChangeData.splice(0, 1);
            console.log(purchasePlanZhuChangeData);
            purchasePlanZhuChangeData.splice(1, 1);
            console.log(purchasePlanZhuChangeData);
            postFormData("purchasePlanZhuChange", purchasePlanZhuChangeData);
        }
        //点击取消修改
        $(".purchasePlanZhuChange .cancel").click(function () {
            $(".purchasePlanZhuChange").addClass("hide");
            console.log(beginData);
        })
        $(".purchasePlanZhuChange .submit").click(function () {
            $(".purchasePlanZhuChange").addClass("hide");
            // alert("修改计划单主表提交修改啦！");
            console.log(getElements("purchasePlanZhuChange"));
            beginData[1] = getElements("purchasePlanZhuChange")[0];
            beginData[3] = getElements("purchasePlanZhuChange")[1];
            beginData[4] = getElements("purchasePlanZhuChange")[2];
            console.log(beginData);
        })
    }
    //采购计划点击修改
    // $(".upd-purchasePlan").click(function (e) {
    //     e.stopPropagation();
    //     if (status == "未执行") {
    //         if (currentPurchasePlanShowDetail != undefined) {
    //             if (currentPurchasePlanShowDetail.children.length == 9) {
    //                 //修改明细
    //                 tip.alert("不可修改", "计划明细", "error", 1500);
    //                 return;
    //             }
    //         }
    //         changePurchasePlan(e);
    //     } else {
    //         tip.alert("此计划已审核，不可进行操作！", "计划", "error", 1500);
    //         return;
    //     }
    // })
    //采购计划点击删除
    $(".del-purchasePlan").click(function () {
        console.log(chooseContractTr);
        if (status == "未执行") {
            console.log(currentPurchasePlanShowDetail);
            if (currentPurchasePlanShowDetail != undefined) {
                if (currentPurchasePlanShowDetail.children.length == 9) {
                    //删除明细
                    $(currentPurchasePlanShowDetail).remove();
                    tip.alert("删除成功", "计划明细", "success", 1500);
                    return;
                } else if (currentPurchasePlanShowDetail.children.length == 6) {
                    //删除整张表
                    tip.alert("此处不可删除主表", "计划表", "error", 1500);
                    return;
                }
            } else {
                tip.alert("删除成功", "计划表", "success", 1500);
                console.log(chooseContractTr);
                $(chooseContractTr).remove();
            }
        } else {
            tip.alert("此计划已审核，不可进行操作！", "计划", "error", 1500);
            return;
        }
    })


    //获取表单数据
    function getElements(ClassName) {
        var form = document.getElementsByClassName(ClassName);
        var model = form[0].firstElementChild;
        var elements = new Array();
        var tagElements = model.getElementsByTagName("input");
        for (var j = 0; j < tagElements.length; j++) {
            elements.push(tagElements[j].value);
        }
        return elements;
    }

    //清空表单数据
    function delFormData(ClassName) {
        var form = document.getElementsByClassName(ClassName);
        var model = form[0].firstElementChild;
        var tagElements = model.getElementsByTagName("input");
        for (var j = 0; j < tagElements.length; j++) {
            tagElements[j].value = "";
        }
    }
    //给表单赋值
    function postFormData(ClassName, arr) {
        var form = document.getElementsByClassName(ClassName);
        var model = form[0].firstElementChild;
        var tagElements = model.getElementsByTagName("input");
        for (var j = 0; j < tagElements.length; j++) {
            tagElements[j].value = arr[j];
        }
    }

    //删除子节点
    function deleteRow(obj, i) {
        if (obj.children.length >= i) {
            obj.removeChild(obj.children[i]);
        }
    }
    //隐藏表格
    function hideTable(obj) {
        obj.children[0].className = "hide";
    }
    // 显示表格
    function showTable(obj) {
        obj.children[0].className = "";
    }
}